package sys.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisUtils {
    @Autowired
    public RedisTemplate redisTemplate;

    public <T> void set(String key, T value){
        redisTemplate.opsForValue().set(key, value);
    }

    public <T> void set(String key, T value, int timeOut, TimeUnit timeUnit){
        redisTemplate.opsForValue().set(key, value, timeOut, timeUnit);
    }

    public <T> T get(String key){
        ValueOperations<String, T> operation = redisTemplate.opsForValue();
        return operation.get(key);
    }

    public boolean del(String key){
        return redisTemplate.delete(key);
    }
}

